package GUI;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;
import GUI.manager.VentanaFactory;
import GUI.manager.VentanaManager;

import core.model.Categoria;
import core.model.Empresa;
import core.model.Producto;
import core.model.Subcategoria;

public class panelBusquedaCodigoTeclado extends javax.swing.JPanel implements
		ActionListener, ItemListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3898228275459460510L;

	public panelBusquedaCodigoTeclado() {
		initComponents();
	}

	private void initComponents() {

		bTitulo = new javax.swing.JButton();
		etiquetaNick = new javax.swing.JLabel();
		botonSalir = new javax.swing.JButton();
		panelCentro = new javax.swing.JPanel();
		bAtras = new javax.swing.JButton();
		eCodigoBarras = new javax.swing.JLabel();
		bBuscar = new javax.swing.JButton();
		tfCodigoBarras = new javax.swing.JTextField();
		tfNombre = new javax.swing.JTextField();
		eNombre = new javax.swing.JLabel();
		tfSubcategoria = new javax.swing.JTextField();
		eSubcategoria = new javax.swing.JLabel();
		tfUnidad = new javax.swing.JTextField();
		tfCategoria = new javax.swing.JTextField();
		eCategoria = new javax.swing.JLabel();
		tfCantidad = new javax.swing.JTextField();
		eCantidad = new javax.swing.JLabel();
		eUnidad = new javax.swing.JLabel();
		eSuper = new javax.swing.JLabel();
		cbSuper = new javax.swing.JComboBox<String>();
		etiquetaEntrada = new javax.swing.JLabel();
		bBusqueda = new javax.swing.JButton();
		bCrearLista = new javax.swing.JButton();
		bAyuda = new javax.swing.JButton();
		bHistorial = new javax.swing.JButton();
		bSugerencias = new javax.swing.JButton();
		bOpciones = new javax.swing.JButton();

		setBackground(new java.awt.Color(255, 255, 255));

		bTitulo.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/encabezadoMain.png")); // NOI18N
		bTitulo.setBorder(null);
		bTitulo.setBorderPainted(false);
		bTitulo.setBackground(new java.awt.Color(255, 255, 255));

		etiquetaNick.setBackground(new java.awt.Color(102, 102, 102));
		etiquetaNick.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		etiquetaNick.setText(panelInicio.nick);
		etiquetaNick.setToolTipText("");

		botonSalir.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/menu-salir.png")); // NOI18N
		botonSalir.setBorderPainted(false);
		botonSalir.addActionListener(this);
		botonSalir.setBackground(new java.awt.Color(255, 255, 255));

		panelCentro.setBackground(new java.awt.Color(255, 255, 255));

		bAtras.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/boton_atras.png")); // NOI18N
		bAtras.setBorder(null);
		bAtras.setBackground(new java.awt.Color(255, 255, 255));
		bAtras.addActionListener(this);

		tfUnidad.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfUnidad.setEditable(false);

		bBuscar.setIcon(new javax.swing.ImageIcon("src/GUI/resources/lupa.jpg")); // NOI18N
		bBuscar.setBorder(null);
		bBuscar.addActionListener(this);

		eUnidad.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eUnidad.setForeground(new java.awt.Color(102, 102, 102));
		eUnidad.setText("UNIDAD");

		tfCantidad.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfCantidad.setEditable(false);

		tfCategoria.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfCategoria.setForeground(new java.awt.Color(102, 102, 102));
		tfCategoria.setEditable(false);

		tfSubcategoria.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfSubcategoria.setForeground(new java.awt.Color(102, 102, 102));
		tfSubcategoria.setEditable(false);

		eCantidad.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eCantidad.setForeground(new java.awt.Color(102, 102, 102));
		eCantidad.setText("CANTIDAD");

		tfNombre.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfNombre.setEditable(false);

		eCodigoBarras.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eCodigoBarras.setForeground(new java.awt.Color(102, 102, 102));
		eCodigoBarras.setText("CODIGO DE BARRAS");

		eCategoria.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eCategoria.setForeground(new java.awt.Color(102, 102, 102));
		eCategoria.setText("CATEGORIA");

		eSubcategoria.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eSubcategoria.setForeground(new java.awt.Color(102, 102, 102));
		eSubcategoria.setText("SUBCATEGORIA");

		eNombre.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eNombre.setForeground(new java.awt.Color(102, 102, 102));
		eNombre.setText("NOMBRE");

		tfCodigoBarras.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N

		
		eSuper.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eSuper.setForeground(new java.awt.Color(102, 102, 102));
		eSuper.setText("SUPER/PRECIO");

		cbSuper.setEnabled(false);
		cbSuper.addItemListener(this);

		org.jdesktop.layout.GroupLayout panelCentroLayout = new org.jdesktop.layout.GroupLayout(panelCentro);
        panelCentro.setLayout(panelCentroLayout);
        panelCentroLayout.setHorizontalGroup(
            panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelCentroLayout.createSequentialGroup()
                .addContainerGap()
                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panelCentroLayout.createSequentialGroup()
                        .add(eSubcategoria, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tfSubcategoria, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .add(panelCentroLayout.createSequentialGroup()
                        .add(eCodigoBarras, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tfCodigoBarras, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE)
                        .add(48, 48, 48)
                        .add(bBuscar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(30, 30, 30))
                    .add(panelCentroLayout.createSequentialGroup()
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(eCategoria, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, eNombre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(tfNombre)
                            .add(tfCategoria, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .add(panelCentroLayout.createSequentialGroup()
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(bAtras)
                            .add(panelCentroLayout.createSequentialGroup()
                                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(eCantidad)
                                    .add(eSuper, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(panelCentroLayout.createSequentialGroup()
                                        .add(tfCantidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 135, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(30, 30, 30)
                                        .add(eUnidad)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(tfUnidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 135, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(cbSuper, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 203, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                        .add(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelCentroLayout.setVerticalGroup(
            panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelCentroLayout.createSequentialGroup()
                .add(22, 22, 22)
                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(eCodigoBarras)
                        .add(tfCodigoBarras, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(bBuscar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(tfNombre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(eNombre))
                .add(18, 18, 18)
                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(eCategoria)
                    .add(tfCategoria, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(eSubcategoria)
                    .add(tfSubcategoria, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(tfCantidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(eCantidad)
                    .add(eUnidad)
                    .add(tfUnidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(eSuper)
                    .add(cbSuper, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 120, Short.MAX_VALUE)
                .add(bAtras)
                .addContainerGap())
        );
        
		etiquetaEntrada.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		etiquetaEntrada.setForeground(new java.awt.Color(243, 15, 120));
		etiquetaEntrada.setText("BIENVENIDO A LISTA DE LA COMPRA MAKER ");

		bBusqueda.setBackground(new java.awt.Color(255, 255, 255));
		bBusqueda.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bBusqueda.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonBusqueda.png")); // NOI18N
		bBusqueda.setToolTipText("");
		bBusqueda.setBorderPainted(false);
		bBusqueda.addActionListener(this);

		bCrearLista.setBackground(new java.awt.Color(255, 255, 255));
		bCrearLista.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bCrearLista.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonCrearLista.png")); // NOI18N
		bCrearLista.setBorderPainted(false);
		bCrearLista.addActionListener(this);

		bAyuda.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bAyuda.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonAyuda.png")); // NOI18N
		bAyuda.setBorderPainted(false);
		bAyuda.setBackground(new java.awt.Color(255, 255, 255));
		bAyuda.addActionListener(this);

		bHistorial.setBackground(new java.awt.Color(255, 255, 255));
		bHistorial.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bHistorial.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonHistorial.png")); // NOI18N
		bHistorial.setBorderPainted(false);
		bHistorial.addActionListener(this);

		bSugerencias.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bSugerencias.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonSugerencias.png")); // NOI18N
		bSugerencias.setBorderPainted(false);
		bSugerencias.addActionListener(this);
		bSugerencias.setBackground(new java.awt.Color(255, 255, 255));

		bOpciones.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bOpciones.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonOpciones.png")); // NOI18N
		bOpciones.setBorderPainted(false);
		bOpciones.setBackground(new java.awt.Color(255, 255, 255));
		bOpciones.addActionListener(this);

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout.createSequentialGroup()
										.add(96, 96, 96).add(bTitulo)
										.add(44, 44, 44).add(botonSalir))
								.add(layout
										.createSequentialGroup()
										.add(84, 84, 84)
										.add(etiquetaEntrada)
										.add(46, 46, 46)
										.add(etiquetaNick,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												280,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
						.addContainerGap(
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE))
				.add(layout
						.createSequentialGroup()
						.addContainerGap()
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.LEADING)
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.TRAILING)
												.add(bCrearLista,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														157,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
												.add(bHistorial,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														157,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
												.add(bSugerencias,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														157,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
												.add(bOpciones,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
														157,
														org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(org.jdesktop.layout.GroupLayout.TRAILING,
												bAyuda,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												157,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.add(bBusqueda,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										155,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
						.add(30, 30, 30)
						.add(panelCentro,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(6, 6, 6)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(bTitulo,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										104,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.add(botonSalir))
						.add(6, 6, 6)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(etiquetaEntrada).add(etiquetaNick))
						.add(18, 18, 18)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createSequentialGroup()
										.add(bBusqueda,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bCrearLista,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bHistorial,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bSugerencias,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bOpciones,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bAyuda,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.add(panelCentro,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
						.addContainerGap(47, Short.MAX_VALUE)));
	}// </editor-fold>
		// Variables declaration - do not modify

	private Empresa obtenerEmpresasByCodigoEmpresa(int codigo_empresa) {
		// TODO Auto-generated method stub
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		Empresa empresa = ventanaManager.findCodigoEmpresa(codigo_empresa);
		return empresa;
	}
	
	private Empresa obtenerPrecio (int codigo_empresa, String codigo_producto) {
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		Empresa empresa = ventanaManager.findPrecio(codigo_empresa, codigo_producto);
		return empresa;
	}
	
	private List<Empresa> obtenerEmpresasByCodigoProducto(String codigo_barras) {
		// TODO Auto-generated method stub
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		List<Empresa> empresas = ventanaManager.findByCodigoProducto(codigo_barras);
		return empresas;
		
	}

	private Producto bucarProducto(String codigo_barras) {
		Producto producto;
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		producto = ventanaManager.findBy(codigo_barras);
		return producto;
	}

	private Categoria buscarCategoria(int codigo_categoria) {
		Categoria categoria;
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		categoria = ventanaManager.getCategoriaByCode(codigo_categoria);
		return categoria;
	}

	private Subcategoria buscarSubcategoria(int codigo_subcategoria) {
		Subcategoria subcategoria;
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		subcategoria = ventanaManager
				.getSubcategoriaByCode(codigo_subcategoria);
		return subcategoria;
	}

	private javax.swing.JButton bAtras;
	private javax.swing.JButton bAyuda;
	private javax.swing.JButton bBuscar;
	private javax.swing.JButton bBusqueda;
	private javax.swing.JButton bCrearLista;
	private javax.swing.JButton bHistorial;
	private javax.swing.JButton bOpciones;
	private javax.swing.JButton bSugerencias;
	private javax.swing.JButton bTitulo;
	private javax.swing.JButton botonSalir;
	private javax.swing.JTextField tfCategoria;
	private javax.swing.JComboBox<String> cbSuper;
	private javax.swing.JTextField tfSubcategoria;
	private javax.swing.JLabel eCantidad;
	private javax.swing.JLabel eCategoria;
	private javax.swing.JLabel eCodigoBarras;
	private javax.swing.JLabel eNombre;
	private javax.swing.JLabel eSubcategoria;
	private javax.swing.JLabel eSuper;
	private javax.swing.JLabel eUnidad;
	private javax.swing.JLabel etiquetaEntrada;
	private javax.swing.JLabel etiquetaNick;
	private javax.swing.JTextField tfCodigoBarras;
	private javax.swing.JPanel panelCentro;
	private javax.swing.JTextField tfCantidad;
	private javax.swing.JTextField tfNombre;
	private javax.swing.JTextField tfUnidad;
	private JFrame actual;
	private JPanel estePanel = this;

		public void actionPerformed(ActionEvent e) {

			if (e.getSource() == bBuscar) {
				String codigo_barras = tfCodigoBarras.getText();
				Producto producto = bucarProducto(codigo_barras);
				Subcategoria subcategoria = buscarSubcategoria(producto.getCodigo_subcategoria());
				Categoria categoria = buscarCategoria(subcategoria.getCodigo_categoria());
				
				tfNombre.setText(producto.getNombre());

				tfCategoria.setText(categoria.getNombre());

				tfSubcategoria.setText(subcategoria.getNombre());
				tfCantidad.setText(String.valueOf(producto.getCantidad()));
				tfUnidad.setText(producto.getUnidad());
				
				// RELLENAR COMBOBOX
				List<String> listaNombresEmpresas = new ArrayList<String>();
				List<Empresa> empresas1 = obtenerEmpresasByCodigoProducto(codigo_barras);
							
				Iterator<Empresa> iterator = empresas1.iterator();
				while (iterator.hasNext()) {
					Empresa empresa = iterator.next();
					listaNombresEmpresas.add(String.valueOf(obtenerEmpresasByCodigoEmpresa(empresa.getCodigo_empresa()).getNombre())+"  "+obtenerPrecio(empresa.getCodigo_empresa(), codigo_barras).getPrecio());
				}
				String[] empresasArrayString = new String[listaNombresEmpresas.size()];
				listaNombresEmpresas.toArray(empresasArrayString);

				cbSuper.setModel(new javax.swing.DefaultComboBoxModel<String>(
						empresasArrayString));
				// FIN
				cbSuper.setEnabled(true);
				cbSuper.setSelectedIndex(0);
				
				//tfPrecio.setText();
				
			}
			if (e.getSource() == bAtras) {

				actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelBusqueda());
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);
			}
			if (e.getSource() == bHistorial) {
				actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelHistorial());
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);

			}
			if (e.getSource() == bSugerencias) {

				actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelSugerencias());
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);
			}
			if (e.getSource() == bOpciones) {
				actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelOpciones());
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);

			}
			if (e.getSource() == bAyuda) {
				actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelAyuda());
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);

			}
			if (e.getSource() == bCrearLista) {
				actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelCrearLista());
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);

			}
			if (e.getSource() == bTitulo) {
				actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelPrincipal());
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);

			}
			if (e.getSource() == botonSalir) {
				actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelSalir(6));
				actual.setPreferredSize(new Dimension(610, 330));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);

			}
		}

		@Override
		public void itemStateChanged(ItemEvent e) {
			// TODO Auto-generated method stub
			if(e.getSource() == cbSuper) {
				//CAMBIAR PRECIO SI CAMBIA COMBO //TODO
			}
		}
}